use regex::Regex;
use std::borrow::Cow;
use std::cell::LazyCell;
use std::collections::HashMap;
use validator::ValidationError;
const MOBILE_PHONE_REGEX: LazyCell<Regex> = LazyCell::new(|| Regex::new(r"^(13[0-9]|14[57]|15[0-35-9]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$").expect("Fail to compile mobile phone regex"));
const DIRECTION_REGEX: LazyCell<Regex> = LazyCell::new(|| Regex::new(r"^([东南西北])$").expect("Fail to compile direction regex"));
pub fn is_mobile_phone(value: &str) -> Result<(), ValidationError> {
    if MOBILE_PHONE_REGEX.is_match(value) {
        Ok(())
    } else {
        Err(build_validation_error("手机号码格式不正确"))
    }
}

pub fn is_direction(value: &str) -> Result<(), ValidationError> {
    if DIRECTION_REGEX.is_match(value) {
        Ok(())
    } else {
        Err(build_validation_error("站点方位格式不正确"))
    }
}
fn build_validation_error(message: &'static str) -> ValidationError {
    ValidationError {
        code: Cow::from("invalid"),
        message: Some(Cow::from(message)),
        params: HashMap::new(),
    }
}
